package common

import (
	"alertmanagerWebhook/config"
	"alertmanagerWebhook/global"
	"fmt"
)

type EmailTransformer struct {
	generator *MessageGenerator
}

func NewEmailTransformer() (*EmailTransformer, error) {
	generator, err := NewMessageGenerator()
	if err != nil {
		return nil, err
	}
	return &EmailTransformer{generator: generator}, nil
}

func (t *EmailTransformer) Transform(notification config.Notification) (interface{}, error) {
	firing, resolved, err := t.generator.GenerateAlertContent(notification,"email")
	if err != nil {
		return nil, err
	}

	return &config.EmailMessage{
		Subject: global.Config.System.ProjectName + "【告警通知】",
		Body:    fmt.Sprintf("%s\n%s", firing, resolved),
	}, nil
}

